﻿package plugin.npcDialog.ui.panels.hctwo
{
    import cmd.*;
    import com.core.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.npcdialogs.*;

    public class RLHechengPanel extends HctwoUI implements INpcDialogContent
    {
        private var newshcgonfig:Object;
        private var itemconfig:Object;
        private var erjiArr:Array;
        private var dj_int:int;
        private var user_sex:int;
        private var userid:int;
        private var _armlevel:int;
        private var _armrein:int;
        private var pz_count:int;
        private var bag_ct:int;
        private var max:int;
        private var mPanelList:Dictionary;
        private var typeindex:int;
        private var rein:int;

        public function RLHechengPanel()
        {
            this.newshcgonfig = ConfigDictionary.data.newsrl;
            this.itemconfig = ConfigDictionary.data.item;
            this.erjiArr = [];
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        protected function OnSmtip(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "<font color = \'#997f60\'>强化装备无法作为合成材料</font>");
            shuomingLink.addEventListener(MouseEvent.MOUSE_OUT, this.OnSmclosetip);
            return;
        }// end function

        protected function OnSmclosetip(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            shuomingLink.removeEventListener(MouseEvent.MOUSE_OUT, this.OnSmclosetip);
            return;
        }// end function

        protected function Onfanhui(event:MouseEvent) : void
        {
            hcLVbox.visible = true;
            erjibox.visible = false;
            shuomingLink.visible = false;
            fanhuiLink.visible = false;
            return;
        }// end function

        protected function OnClick60(event:MouseEvent) : void
        {
            erjibox.visible = true;
            hcLVbox.visible = false;
            shuomingLink.visible = true;
            fanhuiLink.visible = true;
            this.dj_int = ((event.currentTarget as LinkButton).parent as Component).dataSource.level;
            this._armlevel = ((event.currentTarget as LinkButton).parent as Component).dataSource.armlevel;
            this.showlist(this.dj_int);
            return;
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            this.showlist(this.dj_int);
            return;
        }// end function

        private function showlist(param1:int) : void
        {
            var _loc_2:String = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            if (this.userid == 1)
            {
                _loc_2 = "战士";
            }
            else if (this.userid == 2)
            {
                _loc_2 = "法师";
            }
            else
            {
                _loc_2 = "道士";
            }
            this.erjiArr = [];
            this.bag_ct = this.getallcount(this.dj_int);
            titleLb.text = this._armlevel + "级" + _loc_2 + "装备合成";
            for each (_loc_3 in this.newshcgonfig)
            {
                
                if (_loc_3.level == param1)
                {
                    if (_loc_3.career == this.userid && _loc_3.sex == 2 || _loc_3.career == this.userid && _loc_3.sex == this.user_sex)
                    {
                        _loc_4 = {};
                        _loc_4.cfg = this.itemconfig[_loc_3.id];
                        _loc_4.armlevel = _loc_3.armlevel;
                        _loc_4.level = _loc_3.level;
                        this.erjiArr.push([_loc_4.cfg, _loc_4.armlevel, _loc_4.level]);
                        this.pz_count = _loc_3.count;
                    }
                }
            }
            _list.array = this.erjiArr;
            _list.renderHandler = new Handler(this.ComlistRander);
            return;
        }// end function

        private function ComlistRander(param1:Component, param2:int) : void
        {
            var _loc_3:Label = null;
            var _loc_4:LinkButton = null;
            var _loc_5:LinkButton = null;
            if (param2 < _list.array.length)
            {
                _loc_3 = param1.getChildByName("xuyaoLabel") as Label;
                _loc_4 = param1.getChildByName("lvname") as LinkButton;
                _loc_4.label = _list.array[param2][1] + "级" + _list.array[param2][0].leixing;
                _loc_3.text = "任意" + _list.array[param2][2] + "级装备  X" + this.pz_count + "=";
                _loc_4.removeEventListener(MouseEvent.MOUSE_OVER, this.OnOverlvtips);
                _loc_4.addEventListener(MouseEvent.MOUSE_OVER, this.OnOverlvtips);
                _loc_5 = param1.getChildByName("hcname") as LinkButton;
                _loc_5.addEventListener(MouseEvent.CLICK, this.OnClickbtn);
                if (this.bag_ct < this.pz_count)
                {
                    _loc_5.labelColors = "0x73716B";
                    _loc_3.color = "0x73716B";
                    _loc_4.labelColors = "0x73716B";
                }
                else
                {
                    _loc_5.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    _loc_3.color = "0x53b436";
                    _loc_4.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                }
            }
            return;
        }// end function

        private function btntip(param1) : void
        {
            param1.disabled = false;
            param1.addEventListener(MouseEvent.MOUSE_OVER, this.OnOverlvtips);
            return;
        }// end function

        protected function OnOverlvtips(event:MouseEvent) : void
        {
            var _loc_2:* = ((event.currentTarget as LinkButton).parent as Component).dataSource;
            _loc_2[0].wear = 0;
            ModelProxy.change("tips", "arm", {data:_loc_2, p:new Point(event.stageX, event.stageY)});
            event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            return;
        }// end function

        protected function OnCloselvtips(event:MouseEvent) : void
        {
            event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        protected function OnClickbtn(event:MouseEvent) : void
        {
            if (this.bag_ct < this.pz_count)
            {
                WarningManager.show(70);
                return;
            }
            var _loc_2:* = ((event.currentTarget as LinkButton).parent as Component).dataSource[0].itemid;
            PluginManager.instance.sendToServer("qianghua", CMDQiangHua.DoCompound2, _loc_2);
            return;
        }// end function

        public function getallcount(param1:int) : int
        {
            var _loc_6:Object = null;
            var _loc_7:Number = NaN;
            var _loc_2:int = 0;
            var _loc_3:* = UserData.getBagData();
            var _loc_4:* = _loc_3.maxcount;
            var _loc_5:int = 1;
            while (_loc_5 < _loc_4)
            {
                
                _loc_6 = _loc_3[_loc_5];
                if (_loc_6)
                {
                    if (_loc_6[4] && _loc_6[4].uselv == param1 && _loc_6[4].superlevel == 0)
                    {
                        if (_loc_6[3] > 0)
                        {
                            _loc_7 = ModelProxy.getValue("data", "servertime") + Number(getTimer());
                            if (_loc_6[3] < _loc_7)
                            {
                                ;
                            }
                        }
                        _loc_2 = _loc_2 + _loc_6[1];
                    }
                }
                _loc_5++;
            }
            return _loc_2;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            var _loc_7:String = null;
            var _loc_8:Object = null;
            var _loc_9:int = 0;
            var _loc_10:Object = null;
            hcLVbox.visible = true;
            this.userid = UserData.getUserData("career");
            var _loc_3:* = UserData.getUserData();
            this.user_sex = _loc_3.sex;
            this.rein = _loc_3.rein;
            erjibox.visible = false;
            shuomingLink.visible = false;
            fanhuiLink.visible = false;
            fanhuiLink.addEventListener(MouseEvent.CLICK, this.Onfanhui);
            shuomingLink.addEventListener(MouseEvent.MOUSE_OVER, this.OnSmtip);
            var _loc_4:Array = [];
            var _loc_5:Array = [];
            var _loc_6:Array = [];
            txt_desc.text = "神威狱，刷新前期小BOSS，易击杀，刷新快，掉落1转之前全职业装备和副本卷轴";
            txt_desc.align = "left";
            if (this.userid == 1)
            {
                _loc_7 = "战士";
            }
            else if (this.userid == 2)
            {
                _loc_7 = "法师";
            }
            else
            {
                _loc_7 = "道士";
            }
            title_hec.text = _loc_7 + "套装合成";
            for each (_loc_8 in this.newshcgonfig)
            {
                
                if (_loc_8.armlevel)
                {
                    _loc_6.push(_loc_8.armlevel);
                }
            }
            _loc_5 = this.filterArray(_loc_6);
            _loc_5.sort(Array.NUMERIC);
            _loc_9 = 0;
            while (_loc_9 < _loc_5.length)
            {
                
                for each (_loc_10 in this.newshcgonfig)
                {
                    
                    if (_loc_10.armlevel == _loc_5[_loc_9])
                    {
                        _loc_4.push(_loc_10);
                        break;
                    }
                }
                _loc_9++;
            }
            LIsthec.array = _loc_4;
            LIsthec.renderHandler = new Handler(this.Listrend);
            return;
        }// end function

        private function Listrend(param1:Component, param2:int) : void
        {
            var _loc_3:LinkButton = null;
            if (param2 < LIsthec.length)
            {
                _loc_3 = param1.getChildByName("lvLabel60") as LinkButton;
                _loc_3.label = "合成" + LIsthec.array[param2].armlevel + "级装备";
                if (LIsthec.array[param2].id != LIsthec.array[param2].armlevel)
                {
                    _loc_3.labelColors = "0x53b436,0xe19f21,0x53b436,0xe19f21";
                    _loc_3.addEventListener(MouseEvent.CLICK, this.OnClick60);
                }
                else
                {
                    _loc_3.labelColors = "0x73716B";
                    _loc_3.addEventListener(MouseEvent.MOUSE_OVER, this.OnClicktips);
                }
            }
            return;
        }// end function

        protected function OnClicktips(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "<font color = \'#997f60\'>尚未开放</font>");
            event.target.addEventListener(MouseEvent.MOUSE_OUT, this.closeTips);
            return;
        }// end function

        protected function closeTips(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            event.target.removeEventListener(MouseEvent.MOUSE_OUT, this.closeTips);
            return;
        }// end function

        private function filterArray(param1:Array) : Array
        {
            var _loc_2:Array = [];
            var _loc_3:* = param1.length;
            var _loc_4:uint = 0;
            while (_loc_4 < _loc_3)
            {
                
                if (_loc_2.indexOf(param1[_loc_4]) == -1)
                {
                    _loc_2.push(param1[_loc_4]);
                }
                _loc_4 = _loc_4 + 1;
            }
            return _loc_2;
        }// end function

        public function upSucess() : void
        {
            return;
        }// end function

    }
}
